import { http } from "@/utils/http/axios";
import { RequestEnum } from "@/enums/httpEnum";

/**
 * 获取文件预览地址
 */
export const getFilePreviewUrl = () => {
  return http.request({
    url: `/common/config/previewUrl`,
    method: RequestEnum.GET
  }, {
    isTransformResponse: false
  })
}

/**
 * 获取公众号二维码链接
 */
export const getWxmpQrCodeUrl = () => {
  return http.request({
    url: `/common/config/qrcodeUrl`,
    method: RequestEnum.GET
  }, {
    isTransformResponse: false
  })
}

/**
 * 获取系统配置分页
 */
export const getConfigPage = ({pageNum, pageSize}) => {
  return http.request({
    url: `/config/page/${pageNum}/${pageSize}`,
    method: RequestEnum.GET
  })
}

/**
 * 添加系统配置
 */
export const addConfig = (data: {
  configName: string,
  configKey: string,
  configValue: string,
  remark?: string
}) => {
  return http.request({
    url: '/config',
    method: RequestEnum.POST,
    data
  }, {
    isTransformResponse: false
  })
}

/**
 * 修改系统配置
 */
export const updateConfig = (id, data: {
  configName: string,
  configKey: string,
  configValue: string,
  remark?: string
}) => {
  return http.request({
    url: `/config/${id}`,
    method: RequestEnum.PUT,
    data
  }, {
    isTransformResponse: false
  })
}

/**
 * 删除系统配置
 */
export const deleteConfig = id => {
  return http.request({
    url: `/config/${id}`,
    method: RequestEnum.DELETE
  }, {
    isShowSuccessMessage: true
  })
}
